package com.hioove.core.aop.model;

import com.hioove.core.model.base.config.MethodSupport;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * 统计程序aop 所有的方法
 */
public class MethodEnhance {
    // 程序所有切面信息
    private List<MethodSupport> pointcut;
    // 切面前置拦截
    private List<MethodSupport> before;
    // 切面后置拦截
    private List<MethodSupport> after;
    // 切面后置拦截 方法正常执行后拦截
    private List<MethodSupport> afterReturning;
    // 切面后置拦截 方法异常执行后拦截
    private List<MethodSupport> afterThrowing;
    // 切面的环绕拦截
    private List<MethodSupport> around;

    public List<MethodSupport> getBefore() {
        return before;
    }

    public void addBefore(MethodSupport before) {
        this.before = Optional.ofNullable(this.before).orElseGet(ArrayList<MethodSupport>::new);
        this.before.add(before);
    }

    public List<MethodSupport> getAfter() {
        return after;
    }

    public void addAfter(MethodSupport after) {
        this.after = Optional.ofNullable(this.after).orElse(new ArrayList<>());
        this.after.add(after);
    }

    public List<MethodSupport> getPointcut() {
        return pointcut;
    }

    public void addPointcut(MethodSupport pointcut) {
        this.pointcut = Optional.ofNullable(this.pointcut).orElseGet(ArrayList<MethodSupport>::new);
        this.pointcut.add(pointcut);
    }

    public List<MethodSupport> getAfterReturning() {
        return afterReturning;
    }

    public void addAfterReturning(MethodSupport afterReturning) {
        this.afterReturning = Optional.ofNullable(this.afterReturning).orElseGet(ArrayList<MethodSupport>::new);
        this.afterReturning.add(afterReturning);
    }

    public List<MethodSupport> getAfterThrowing() {
        return afterThrowing;
    }

    public void addAfterThrowing(MethodSupport afterThrowing) {
        this.afterThrowing = Optional.ofNullable(this.afterThrowing).orElseGet(ArrayList<MethodSupport>::new);
        this.afterThrowing.add(afterThrowing);
    }

    public List<MethodSupport> getAround() {
        return around;
    }

    public void addAround(MethodSupport around) {
        this.around = Optional.ofNullable(this.around).orElseGet(ArrayList<MethodSupport>::new);
        this.around.add(around);
    }
}
